/**
 * Created by Administrator on 2017/1/10.
 */
import {Observable}                         from 'rxjs/Observable';
import {Component,OnInit,ViewChild}         from '@angular/core';
import {HomeService} from "./homeService";
import {KSSwiperContainer, KSSwiperSlide}    from 'angular2-swiper';
import { InfiniteScroll } from 'angular2-infinite-scroll';


@Component({
  // moduleId : module.id,
  selector: 'home',
  styleUrls: ["./home.less"],
  templateUrl: './home.html',
  providers :[HomeService]
})
export class Home implements OnInit{
  // this is how you get access to the child component
    @ViewChild(KSSwiperContainer) swiperContainer: KSSwiperContainer;
    homeData : any;
    sideBarFlag:any;
    sideBarConFlag:any;
    isShowBacktop:any;

    constructor(private homeService:HomeService){ }
    ngOnInit():void{
    //  this.homeData = this.homeService.getHomeData().subscribe(
    //    function onNext(x) { console.log('Result: ' ,x); this.homeData =  x},   // 能console出来，并且x获取出来了。但是表单上没有数据。
    //    function onError(err) { console.log('Error: ' , err); },
    //    function onCompleted() {
    //      console.log('Completed',this);
    //    })
        this.homeData = this.homeService.getHomeData().subscribe(res =>this.homeData = res);
    }

    //显示侧边栏
    showSidebar():void{
      this.sideBarFlag=true;
      setTimeout(()=>{
        this.sideBarConFlag=true;
      },400);
    }
    //关闭侧边栏
    closeSlidebar():void{
      this.sideBarFlag=false;
      this.sideBarConFlag=false;
    }

  //监听 scroll 向上滚动
  onScroll():void{
      this.isShowBacktop=false;
    }
  //监听 scroll 向下滚动
  onScrollDown():void{
    this.isShowBacktop=true;
  }
  //点击回到顶部
  backTop():void{
    document.querySelector(".confixSet").scrollTop=0;
  }
}
